<?php
class calon_adik_asuh extends MY_Controller{
    function calon_adik_asuh(){
        parent::MY_Controller();
        $this->data['title'] = 'Master Data Calon Adik Asuh';
        $this->load->model('m_calon_adik_asuh');
        $this->load->model('m_kelas');
        $this->load->model('m_tahun_ajaran');
    }
    var $data;
    var $limit = 10;
    function index(){
        $this->get_calon_adik_asuh('all','nama','asc',0);
    }
    function search(){
        $params = "nama_".$this->input->post('nama');
        $url = $this->input->post('url');
        redirect("$url/$params/0/");
    }
    function get_calon_adik_asuh($params = 'all',$sortBy,$type = 'asc',$offset = 0){
        $option = parsing_param1($params);
        $this->data['searchLink'] = 'calon_adik_asuh/get_calon_adik_asuh';
        $this->data['content'] = "calon_adik_asuh/v_calon_adik_asuh";
        
        $uri_segment = 6;
        if($offset != 0){
          $offset = $this->uri->segment($uri_segment);  
        }
        $num_rows = $this->m_calon_adik_asuh->getCountRows($option);
        $this->data['listCalonAdikAsuh'] = $this->m_calon_adik_asuh->getListCalonAdikAsuh($offset,$this->limit,$option,$sortBy,$type);
        $config['base_url'] = site_url("calon_adik_asuh/get_calon_adik_asuh")."/".$params."/nama/$type";
        $config['uri_segment'] = $uri_segment;
        $config['total_rows'] = $num_rows;
        $config['per_page'] = $this->limit;
        $this->pagination->initialize($config);
        $this->data['pagination'] = $this->pagination->create_links();
        $this->data['offset'] = $offset;
        if($type == 'asc'){
            $type = 'desc';
        }else $type = 'asc';
        $this->data['sortNama'] = site_url("calon_adik_asuh/get_calon_adik_asuh/".$id)."/".$params."/nama/$type";
        
        $this->render($this->data);
    }
    function add_calon_adik_asuh_form($params = "all",$sortBy,$type = 'asc',$offset = 0){
        $option = parsing_param1($params);
        $this->data['searchLink'] = "calon_adik_asuh/add_calon_adik_asuh_form";
        
        $this->data['content'] = "calon_adik_asuh/v_calon_adik_asuh";
        $this->data['subLink'] = "calon_adik_asuh/add_calon_adik_asuh_proses";
        $this->data['formTitle'] = "Form Tambah Data Calon Adik Asuh";
        $this->data['formView'] = "calon_adik_asuh/addCalonAdikAsuhForm";
        
        $uri_segment = 6;
        if($offset != 0){
          $offset = $this->uri->segment($uri_segment);  
        }
        $num_rows = $this->m_calon_adik_asuh->getCountRows($option);
        $this->data['listCalonAdikAsuh'] = $this->m_calon_adik_asuh->getListCalonAdikAsuh($offset,$this->limit,$option,$sortBy,$type);
        $this->data['listKelas'] = $this->m_kelas->getListKelas();
        $this->data['listTahunAjaran'] = $this->m_tahun_ajaran->getActiveTahunAjaran();
        $config['base_url'] = site_url("calon_adik_asuh/add_calon_adik_asuh_form")."/".$params."/nama/$type";
        $config['uri_segment'] = $uri_segment;
        $config['total_rows'] = $num_rows;
        $config['per_page'] = $this->limit;
        $this->pagination->initialize($config);
        $this->data['pagination'] = $this->pagination->create_links();
        $this->data['offset'] = $offset;
        if($type == 'asc'){
            $type = 'desc';
        }else $type = 'asc';
        $this->data['sortNama'] = site_url("calon_adik_asuh/add_calon_adik_asuh_form/".$id)."/".$params."/nama/$type";
        
        $this->render($this->data);
    }
    function edit_calon_adik_asuh_form($id,$params = "all",$sortBy,$type = 'asc',$offset = 0){
        $option = parsing_param1($params);
        $this->data['searchLink'] = "calon_adik_asuh/edit_calon_adik_asuh_form/$id";
        $this->data['sortLink'] = site_url("calon_adik_asuh/edit_calon_adik_asuh_form/".$id)."/".$params."/$sortBy/$type";
        
        $this->data['content'] = "calon_adik_asuh/v_calon_adik_asuh";
        $this->data['subLink'] = "calon_adik_asuh/edit_calon_adik_asuh_proses";
        $this->data['formTitle'] = "Form Edit Data Calon Adik Asuh";
        $this->data['formView'] = "calon_adik_asuh/editCalonAdikAsuhForm";
        $this->data['dataInput'] = $this->m_calon_adik_asuh->getCalonAdikAsuhById($id);
        
        $uri_segment = 7;
        if($offset != 0){
          $offset = $this->uri->segment($uri_segment);  
        }
        $num_rows = $this->m_calon_adik_asuh->getCountRows($option);
        $this->data['listCalonAdikAsuh'] = $this->m_calon_adik_asuh->getListCalonAdikAsuh($offset,$this->limit,$option,$sortBy,$type);
        $this->data['listKelas'] = $this->m_kelas->getListKelas();
        $this->data['listTahunAjaran'] = $this->m_tahun_ajaran->getActiveTahunAjaran();
        $config['base_url'] = site_url("calon_adik_asuh/edit_calon_adik_asuh_form/".$id)."/".$params."/nama/$type";
        $config['uri_segment'] = $uri_segment;
        $config['total_rows'] = $num_rows;
        $config['per_page'] = $this->limit;
        $this->pagination->initialize($config);
        $this->data['pagination'] = $this->pagination->create_links();
        $this->data['offset'] = $offset;
        if($type == 'asc'){
            $type = 'desc';
        }else $type = 'asc';
        $this->data['sortNama'] = site_url("calon_adik_asuh/edit_calon_adik_asuh_form/".$id)."/".$params."/nama/$type";
        
        $this->render($this->data);
    }
    function detail_calon_adik_asuh($id){
        $this->data['content'] = "calon_adik_asuh/detailCalonAdikAsuh";
        $this->data['listCalonAdikAsuh'] = $this->m_calon_adik_asuh->getCalonAdikAsuhById($id);
        $this->data['linkBack'] = site_url('calon_adik_asuh/get_calon_adik_asuh');
        $this->data['titlePage'] = "Detail Calon Adik Asuh";
        $this->data['subLink'] = "calon_adik_asuh/add_dinamis_calon_adik_asuh_proses";
        $this->data['dinamisCalonAdikAsuh'] = $this->m_calon_adik_asuh->getDinamisCalonAdikAsuh($id);
        
        $this->render($this->data);
    }
    function add_calon_adik_asuh_proses(){
        $insert = $this->m_calon_adik_asuh->addCalonAdikAsuh($_POST);
        if($insert == TRUE){
            $this->session->set_flashdata("message",1);
        }else{
            $this->session->set_flashdata("message",2);
        }
        
        redirect("calon_adik_asuh");
    }
    function edit_calon_adik_asuh_proses(){
        $update = $this->m_calon_adik_asuh->editCalonAdikAsuh($_POST);
        if($update == TRUE){
            $this->session->set_flashdata("message",1);
        }else{
            $this->session->set_flashdata("message",2);
        }
        
        redirect("calon_adik_asuh");
    }
    function delete_calon_adik_asuh($id){
        $delete = $this->m_calon_adik_asuh->deleteCalonAdikAsuh($id);
        if($delete == TRUE){
            $this->session->set_flashdata("message",3);
        }else{
            $this->session->set_flashdata("message",4);
        }
        
        redirect("calon_adik_asuh");
    }
    function add_dinamis_calon_adik_asuh_proses(){
        $data = array('tanggal' => date('Y-m-d'),
            'id_adik_asuh' => $this->input->post('idCalonAdikAsuh'),
            'alamat' => $this->input->post('alamat'),
            'no_telp' => $this->input->post('noTelp'),
            'jumlah_saudara' => $this->input->post('jumSaudara'),
            'id_sekolah' => $this->input->post('idSekolah'),
            'id_kelas' => $this->input->post('kelas'),
            'id_tahun_ajaran' => $this->input->post('id_tahun_ajaran'),
            'status' => '1');
        
        $insert = $this->m_calon_adik_asuh->addDinamisCalonAdikAsuh($data);
        if($insert == TRUE){
            $this->session->set_flashdata("message",1);
        }else{
            $this->session->set_flashdata("message",2);
        }
        
        redirect('calon_adik_asuh/detail_calon_adik_asuh/'.$this->input->post('idCalonAdikAsuh'));
    }
}
?>
